package com.ly.work.singleThread;

public class Demo01 {
    //私有化构造器
    private Demo01(){

    }

    //声明对象
    private static Demo01 single=null;

    //声明一个变量测试是否生成第二个对象
    private  static int i=0 ;

    //静态工厂方法
    public static Demo01 getInstance() {
        if (single == null) {
//          加同步锁,
            synchronized (Object.class) {

                if (single==null) {
                    single = new Demo01();
                    System.out.println("对象生成");
                    i++;
                }
           }

        }
        return single;
    }
}
